home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 002 / wsstrip.arc / HGETSTR.C next >
Encoding:
C/C++ Source or Header  |  1986-11-13  |  1.0 KB  |  26 lines

  1. /* This function is from "The C Toolbox" by William James Hunt   */
  2. /* (Addison-Wesley, 1985)                                        */
  3.  
  4. /* getstr.c - get a line of input from keyboard */
  5. /* like fgets(...stdin) but doesnot place the '\n' in the string */
  6.  
  7. #include <stdio.h>
  8.  
  9. int getstr(s,maxs)              /* get a line of input */
  10.  char s[] ;                     /* place the input here in string form */
  11.  int maxs ;                     /* limit on characters allowed */
  12.  {                              /* returns string length */
  13.    int i , c ;
  14.  
  15.    i=0 ;
  16.    c = getchar() ;              /* get first character */
  17.                                 /* repeat til full, EOF or end-of-line */
  18.    while( (i < maxs) && (c != '\n') && ( c != EOF) )
  19.      { s[i] = c ;               /* place char in string */ 
  20.        i = i + 1 ;              /* advance char count  */
  21.        c = getchar() ;          /* and get another character */
  22.      }
  23.    s[i] = '\0' ;
  24.    return( i ) ;                /* return count of characters */
  25.  }
  26.